<?php
//关闭事物自动提交
$db->mysqlDB->falseAutoCommit();

//获取请求必传参
$requestParams = $route->bodyParams['ap_request_params'];

//删除请求参数中的请求必传参
unset($route->bodyParams['ap_request_params']);

//取出所属菜单ID
$belongsMenuID = $route->bodyParams['belongsMenu'];

//删除所属菜单参数
unset($route->bodyParams['belongsMenu']);

//保存新增成功后的ID
$R1 = $db->mysqlDB->automaticAdd($route->bodyParams)->insert("sys_action_permissions");

//判断是否有选择菜单
if($belongsMenuID != NULL){

    //新增所属菜单操作
    $insertArr = [
        "mapm_mid"  => $belongsMenuID[count($belongsMenuID) - 1],
        "mapm_apid" => $R1
    ];

    $R3 = $db->mysqlDB->automaticAdd($insertArr)->insert("sys_menu_action_permissions_middle");

}


//判断是否需要增加请求参数信息
if(count($requestParams) <= 0){

    $db->mysqlDB->actionCommint();
    $db->mysqlDB->trueAutoCommit();
    $response->responseData(true);

}

//拼接多新增语句SQL
$addRequestSql = "INSERT INTO sys_request_parameter";

$keys = "(rp_apid,rp_name,rp_is_must,rp_rule,rp_type,rp_note,rp_way) VALUES";

$values = "";

for($i=0;$i<count($requestParams);$i++){

    $paramsName   = trim($requestParams[$i]['rp_name']);
    $paramsRule   = trim($requestParams[$i]['rp_rule']);
    $paramsIsMust = trim($requestParams[$i]['rp_is_must']);
    $paramsType   = trim($requestParams[$i]['rp_type']);
    $paramsNote   = trim($requestParams[$i]['rp_note']);
    $paramsWay    = trim($requestParams[$i]['rp_way']);

    $tmpValue = "(";
    $tmpValue .= $R1 . ",'" . $paramsName . "',".$paramsIsMust.",'" . $paramsRule . "','" . $paramsType . "','" . $paramsNote . "','" . $paramsWay . "'";
    $tmpValue .= "),";

    $values .= $tmpValue . "";

}

//拼接最终SQL
$addRequestSql .= $keys .= rtrim($values, ",");

//执行SQL
$R2 = $db->mysqlDB->queryTransaction($addRequestSql);

//判断两个操作是否执行成功
if (!$R1 || !$R2) {
    $db->mysqlDB->rollBackCommint();
    $response->responseData(false);
}else{
    $db->mysqlDB->actionCommint();
    $db->mysqlDB->trueAutoCommit();
}

$response->responseData(true);




